//
// Created by mac on 2/20/22.
//

#include <vector>
using namespace std;

vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
    vector<vector<int>> res;
    int size = intervals.size();
    int i=0;
    while (i<size && intervals[i][1]<newInterval[0]){
        res.push_back(intervals[i]);
        i++;}

    while (i<size && intervals[i][0]<=newInterval[1]){
        newInterval[0] = min(intervals[i][0], newInterval[0]);
        newInterval[1] = max(intervals[i][1], newInterval[1]);
        i++;
    }
    res.push_back(newInterval);
    while (i<size){
        res.push_back(intervals[i]);
        i++;
    }
    return res;
}